﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_MailGetCompleteList]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_MailGetCompleteList];
GO
-------------------------------------------------------------------------------
-- sproc_MailGetCompleteList
-------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[sproc_MailGetCompleteList]
(
    @Username             nvarchar(20),
    @MailFolderType     int
)
AS
BEGIN

SET NOCOUNT ON;

--得到某用户某收件夹中的邮件完整信息
--1    收件
--2    我的发件
--3    我的回收
SELECT
        a.*,
        (select count(*) from TabMailAttachFiles where MailID = a.MailID) AS attnumber,
        b.classname as classname
    FROM
        TabMailList a
        left outer join uds_class b on a.classid = b.classid
    WHERE
        a.MailReceiver = @Username
        AND a.MailFolderType = @MailFolderType
    ORDER BY a.MailID DESC

END
GO